/**
 * 
 */
package com.googlecode.cswish.model;

import java.util.HashMap;
import java.util.Map;

/**
 * Only store the permitted parameter value
 * 
 * @author Jerry.Feng Date: 2008-4-5
 *
 */
public class DynamicActionProxy extends HashMap<String, Object> {

	private static final long serialVersionUID = -6918972421768448473L;

	private Map<String, Class<?>> parameterType = new HashMap<String, Class<?>>();
	
	public DynamicActionProxy() {
		super();
	}
	
	public DynamicActionProxy(int initialCapacity) {
		super(initialCapacity);
	}
	
	/**
	 * add the permitted parameter name and type
	 * 
	 * @param name
	 * @param type
	 */
	public void setType(String name, Class<?> type) {
		parameterType.put(name, type);
	}
	
	public Class<?> getType(String name) {
		return parameterType.get(name);
	}
	
	/**
	 * Only the permitted parameter and value can be set to this Map
	 */
	@Override
	public Object put(String name, Object value) {
		Class<?> type = getType(name);
		if (type == null) {
			return null;
		}
		
		if (value != null) {
			// TODO: type check, boolean <--> Boolean
			//type.cast(value);
		}
		return super.put(name, value);
	}
	
	@Override
	public Object get(Object name) {
		return super.get(name);
	}
}